<template>
	<div class="port-page">
		<!-- 顶部按钮 -->
		<div class="but1">
        <router-link to="/home">
         	<el-button type="warning" size="small" class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
        </router-link>
        <el-button type="success"   size="small" class="add btn" style=' margin-top:10px;margin-right: 10px;' @click='componentsShow("ryqxsz")' icon="el-icon-edit">职位权限设置</el-button>
        </div>
		<!-- 模糊搜索条件 -->
		<div class="search">
		</div>
		<!-- 数据表格展示区域 -->
		<!-- 分页查询区域 -->
		<!-- 各个组件显示区域 -->
		<!-- 动画加载 -->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<RyqxszComponent v-if="portComponents.ryqxsz.toggle" @close="componentsHide" :params="portComponents.ryqxsz.params"></RyqxszComponent>
		
		<!-- 添加组件 -->
		<!-- 子路由显示区域 -->
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import RyqxszComponent from './ryqxsz'
	import qs from 'qs'
	export default {
 		props: ['params'],
		components: { LoadingComponent, RyqxszComponent},
		data() {
			return {
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的
				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/
				portComponents: {
					/* 单行删除  */
					singleDelete: {
						type: 'singleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'single',
							title: '此操作将删除该记录?, 是否继续?'
						}
					},
					/* 批量删除 */
					multipleDelete: {
						type: 'multipleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'multiple',
							title: '此操作将删除您选中的记录?, 是否继续?'
						}
					},
//					/* 添加 */
					ryqxsz: {
						type: 'ryqxsz',
						toggle: true,
						params: '',
						data: {}
					},
//					/* 编辑 */
//					edit: {
//						type: 'edit',
//						toggle: false,
//						params: '',
//						data: {}
//					},
//					/* info */
//					info: {
//						type: 'info',
//						toggle: false,
//						params: '',
//						data: {}
//					},
//					btg: {
//                      type: 'btg',
//                      toggle: false,
//                      params: '',
//                      data: {}
//                  },
//                  tg: {
//                      type: 'tg',
//                      toggle: false,
//                      params: '',
//                      data: {}
//                  }
				},
				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [

					{
						prop: 'id',
						label: '',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'xxid',
						label: '学校id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpid',
						label: '物品id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpmc',
						label: '物品名称',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'sl',
						label: '报损数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					
//					{
//						prop: 'jsr',
//						label: '经手人',
//						hide: 0,
//						align: 'center',
//						fixed: false,
//						width: '100',
//						minWidth: '',
//						headerAlign: 'center',
//						formatter: function(row, column) {}
//					},

					{
						prop: 'bsrmc',
						label: '报损人员',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '120',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'jsrmc',
						label: '报损审核人',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '120',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					}
					,{
						prop: 'ztmc',
						label: '审核状态',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '95',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'sj',
						label: '报损时间',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '170',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'bsyy',
						label: '报损原因',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},

				]
			}
		},
		created() {
			//权限
        	        var logininfo = JSON.parse(localStorage.logininfo) ;
			//加载页面时调用
                  this.$store.dispatch('changeTitle','职位权限设置');//修改title
			this.$store.dispatch('changeRouterIndex', '/admin/zwqxsz'); //修改路由
			this.search(); //分页获取默认数据
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			styletest(boj){
            if(this.dataList[boj.rowIndex].ztmc == '不通过'){
              return ' background:#DBD6D6'
            }
    				return '';
    			},
			
			shenhe(type, id , wpid,sl) {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					id: id,
					zt: type,
					wpid:wpid,
					cnt:sl,
					yhid: logininfo.id,
					xxid: logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'wpbs/bschk', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.search();
							this.$store.state.loading = false;
						} else {
						    this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器繁忙，请重试");
						//this.$emit('close', { type: 'add', cancel: false });
						this.$store.state.loading = false;
					})

			},
			search() {
				//查询搜索触发事件
				var time1 = this.$.getLocalTimeNo0(Date.parse(this.vbtime));
	          var time2 = this.$.getLocalTimeNo0(Date.parse(this.vetime));
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params3 = qs.stringify({
					keyword: this.vkeyword, // 关键字报损原因
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					btime:time1,
					etime:time2,
					wpfl:this.wpfl,
					zt:this.visqy,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.axios.post(this.$store.state.api + 'wpbs/list',params3)
				.then(res => {
					let data = res.data.data;
					let list = data.list;
					this.total = data.totalPage;
					this.dataList = list;
					this.searchLoading = false;
				}).catch(res => {
					this.searchLoading = false;
				})
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*if (scope.row.id == 112 && scope.column.property == "iname") {
				    return {
				        color:"red",
				    }
				}else{
				    return {
				        color:"green",
				    }
				}*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall(selection) { //点击全选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				// console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 100px;
            max-width: 135px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
			margin-right: 10px;
		}
		 .but1{
			width: 23%;
			float: left;
		}
		.search{
			width: 77%;
			float: right;
			text-align: right;
		}
		.el-button+.el-button {
            margin-left: 0px;
            margin-top: 8px;
        }
	}
</style>
